< previous page page_184 next page >

Page 184
Public KeyName As String   ' Name of this key
Public ValueNames As Collection ' Values of this key
Those of you accustomed to creating components using Visual Basic will notice the poor design of this class. The fields are accessed publicly instead of through property statements. The class exposes a pure collection object instead of a custom collection. If this were a public object exposed by an ActiveX server, this design would be just asking for trouble.
But this is not a public object exposed by an ActiveX server. It's a private object intended for use within this application. So there is no danger that some outsider might use its properties in an invalid manner. I mention this in the event that you want to expand parts of this sample application into an ActiveX object server at some point. (My book Developing COM/ActiveX Components with Visual Basic 6.0 addresses these issues at some length.)
The EnumerateKeys function uses the GetKeyInfo function (in all its permutations) to obtain information about the subkeys. It will then do the actual enumeration and build a collection of clsKeyValues objects that it can return to the calling function, as follows:
' Enumerate all of the subkeys of this key, returning a collection
' containing clsKeyValues objects
Private Function EnumerateKeys(ByVal hKey As Long) _
As Collection
   Dim NumberOfSubKeys As Long
   Dim MaxSubKeyLength As LongDim res As Long

   ' First, get the number of subkeys and the buffer length we need
      res = GetKeyInfo(hKey, NumberOfSubKeys, MaxSubKeyLength)
   MsgBox "NumberOfSubKeys: " & NumberOfSubKeys & _
   " MaxSubKeyLength: " & MaxSubKeyLength

 
< previous page page_184 next page >